﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SvOtchet.servcontrols
{
   
    public class RedirectorByRole : WebControl
    {

        private Uri urlforadmin;
        public Uri UrlForAdmin
        {
            get { return urlforadmin; }
            set { urlforadmin = value; }
        }
        private Uri urlforuser;
        public Uri UrlForUser
        {
            get { return urlforuser; }
            set { urlforuser = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser();

            if (System.Web.Security.Roles.IsUserInRole(user.UserName, "admin"))
            {
                HttpContext.Current.Response.Redirect(this.UrlForAdmin .ToString(), true);
            }
            else if (System.Web.Security.Roles.IsUserInRole(user.UserName, "user"))
            {
                HttpContext.Current.Response.Redirect(this.UrlForUser .ToString(), true);
            }


        }
    }
}
